package com.aw.guiguzi.bean

import com.aw.baselib.util.AwConvertUtil
import com.aw.baselib.util.AwDataUtil

class AnalysisCombinationItemBean {
    @JvmField
    var type: String? = null
    @JvmField
    var name: String? = null
    var totalCount = 0 //所有数字总数
    @JvmField
    var countAll = 0 //所有数字
    var totalCountPre15 = 0 //前15位总数
    @JvmField
    var countPre15 = 0 //前15位
    var totalCountOutPre15 = 0 //筛除前15位总数
    @JvmField
    var countOutPre15 = 0 //筛除前15位
    var totalCountLimit1 = 0 //限制数量1总数
    @JvmField
    var countLimit1 = 0 //限制数量1
    var totalCountLimit2 = 0 //限制数量2总数
    @JvmField
    var countLimit2 = 0 //限制数量2
    private fun handleResult(param: String): String {
        var param = param
        if (AwDataUtil.isEmpty(param)) {
            return "--"
        }
        if (param.contains("0.")) { //0.8
            param = param.replace("0.", "")
        }
        if (param.length == 1) { //0.8 ==> 8
            param = param + "0"
        } else if (param.startsWith("0")) { //0.08 ==> 08
            param = param.split("".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
        }
        if (param.contains(".0")) { //1.0
            param = param.replace(".0", "00")
        }
        return param
    }

    fun getResultCount(param: Int): String {
        return if (param == 0) {
            "--"
        } else param.toString()
    }

    val rateAll: String
        get() = if (totalCount <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countAll.toDouble(),
                totalCount.toDouble(),
                2
            ).toString()
        )
    val pre15Rate: String
        get() = if (totalCountPre15 <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countPre15.toDouble(),
                totalCountPre15.toDouble(),
                2
            ).toString()
        )
    val rateOutPre: String
        get() = if (totalCountOutPre15 <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countOutPre15.toDouble(),
                totalCountOutPre15.toDouble(),
                2
            ).toString()
        )
    val rateLimit1: String
        get() = if (totalCountLimit1 <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countLimit1.toDouble(),
                totalCountLimit1.toDouble(),
                2
            ).toString()
        )
    val rateLimit2: String
        get() = if (totalCountLimit2 <= 0) {
            "--"
        } else handleResult(
            AwConvertUtil.div(
                countLimit2.toDouble(),
                totalCountLimit2.toDouble(),
                2
            ).toString()
        )

    override fun toString(): String {
        return "AnalysisCombinationItemBean{" +
                "type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", totalCount=" + totalCount +
                ", countAll=" + countAll +
                ", totalCountPre15=" + totalCountPre15 +
                ", countPre15=" + countPre15 +
                ", totalCountOutPre15=" + totalCountOutPre15 +
                ", countOutPre15=" + countOutPre15 +
                ", totalCountLimit1=" + totalCountLimit1 +
                ", countLimit1=" + countLimit1 +
                ", totalCountLimit2=" + totalCountLimit2 +
                ", countLimit2=" + countLimit2 +
                '}'
    }
}